package com.yuhj.ontheway.wq.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.yuhj.ontheway.R;
import com.yuhj.ontheway.clients.ClientApi;
import com.yuhj.ontheway.wq.adaptor.StepsAdapator;
import com.yuhj.ontheway.wq.enty.Dish;
import com.yuhj.ontheway.wq.enty.Step;

public class DishDetailActivity extends Activity {
	private Context mContext;



	private ImageView stepImg;
	private TextView nameTv,burdenTv,introduceTv,stepContentTv;
	private ListView stepLv;
	private int dishId;
	private StepsAdapator dishAdapator;
	private  Step[]  stepsListData ;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.wangqu_dish_detail);
		
		mContext=this.getApplicationContext();
		initViews();
//		new LoaddingData().execute();
		
		
	}
	
	public void initViews() {
		dishAdapator=new StepsAdapator(getApplicationContext());
		Intent intent=getIntent();
		dishId= Integer.parseInt( intent.getStringExtra("id"));
		View headerView=LayoutInflater.from(mContext).inflate(R.layout.wangqu_dish_detail_header, null);
		nameTv=(TextView) headerView.findViewById(R.id.name_tv);
		introduceTv= (TextView) headerView.findViewById(R.id.introduce_tv);
		burdenTv=(TextView) headerView.findViewById(R.id.burden_tv);
		final Dish wangQuData = (Dish) intent
				.getSerializableExtra("wangquData");
		nameTv.setText(wangQuData.getName());
		introduceTv.setText(wangQuData.getTags());
		burdenTv.setText(wangQuData.getIngredients()+wangQuData.getBurden());
//		View stepListView=LayoutInflater.from(mContext).inflate(R.layout.wangqu_dish_detail_item, null);
//		stepLv= (ListView) stepListView.findViewById(R.id.steps_lv);
		stepLv=(ListView) findViewById(R.id.steps_lv);
		stepLv.addHeaderView(headerView);
	//	stepsListData=wangQuData.getSteps();
		dishAdapator.BindData(wangQuData.getSteps());
		stepLv.setAdapter(dishAdapator);
		dishAdapator.notifyDataSetChanged();
		
	}
	
 
//	class LoaddingData extends AsyncTask<Void, Void, ArrayList<Step>>{
//		/* (non-Javadoc)
//		 * @see android.os.AsyncTask#doInBackground(Params[])
//		 */
//		@Override
//		protected ArrayList<Step> doInBackground(Void... arg0) {
//			 
//	//		Toast.makeText(mContext, "步骤列表长度"+ClientApi.getDishDetail(dishId,mContext).size(), Toast.LENGTH_LONG).show();
//			return ClientApi.getDishDetail(dishId) ;
//		 
//		}
//
//		@Override
//		protected void onPostExecute(ArrayList<Step> result) {
//			// TODO Auto-generated method stub
//			super.onPostExecute(result);
//			if (result == null) {
//			
//				Toast.makeText(DishDetailActivity.this, "网络异常,请检查！", 1)
//						.show();
//			} else {
//				
//				dishAdapator.BindData(result);
//				stepLv.setAdapter(dishAdapator);
//				dishAdapator.notifyDataSetChanged();
//			
//				
//			}
//		}
//
//		
//	}
}

 
